package com.king.collect;

import java.util.Set;

import com.google.common.collect.Sets;

/**
 * @author taomk
 * @version 1.0
 * @since 15-1-25 下午10:50
 */
public class SetTest {

	public static void main(String [] args) {
		// Set集合的交集 并集 差集
		Set<Integer> setA = Sets.newHashSet(1, 2, 3, 4, 5);
		Set<Integer> setB = Sets.newHashSet(4, 5, 6, 7, 8);
		// 并集
		Sets.SetView<Integer> union = Sets.union(setA, setB);
		System.out.print("union :");
		for (Integer integer : union) {
			System.out.print(integer);
		}
		System.out.println();
		// 差集
		Sets.SetView<Integer> difference = Sets.difference(setA, setB);
		System.out.print("difference :");
		for (Integer integer : difference) {
			System.out.print(integer);
		}
		System.out.println();
		// 交集
		Sets.SetView<Integer> intersection = Sets.intersection(setA, setB);
		System.out.print("intersection :");
		for (Integer integer : intersection) {
			System.out.print(integer);
		}
		System.out.println();
	}
}
